package game.utils;

import java.awt.*;

/**
 * @author liuyulai
 * Created with IntelliJ IDEA.
 * Date: 21.5.7
 * Time: 11:21
 * Description: 计算图片移动
 */
public  class ImageChange {
    /**
     * 当前图片刷新的频率
     */
    private int frequency;

    /**
     * 图片计数器(循环动作用
     */
    private int picCount;

    /**
     * 图片下标
     */
    private int picIndex;

    /**
     * 构造器
     *
     * @param frequency 传入需要刷新图片的频率
     */
    public ImageChange(int frequency) {
        this.frequency = frequency;
    }

    /**
     * 角色图片处理
     *
     * @param images 传入一个图片数组
     * @return 返回当前应该绘制的图片(根据下标进行判定
     */
    public Image change(Image[] images) {
        this.picCount++;
        if (this.picCount >= this.frequency) {
            this.picCount = 0;
            this.picIndex++;
        }
        if (this.picIndex >= images.length) {
            this.picIndex = 0;
        }
        return images[picIndex];
    }

}
